import type Earth from "../earth/Earth";
import type { CesiumCommand } from "./Command";
import { CESIUM_ACTION } from "./Command";

/**
 * 指令执行器Options
 */
export interface ExecutorOptions {
	earth: Earth;
}

/**
 * Cesium指令执行器
 */
class Executor {
	private _earth: Earth;
	constructor(options: ExecutorOptions) {
		this._earth = options.earth;
	}

	/**
	 * 执行命令
	 * @param cmd : CesiumCommand
	 */
	public run(cmd: CesiumCommand) {
		switch (cmd.action) {
			case CESIUM_ACTION.FLY_TO: {
				this._flyTo(cmd.params);
				break;
			}
			case CESIUM_ACTION.SET_VIEW: {
				this._setView(cmd.params);
			}
			case CESIUM_ACTION.SET_ORIENTATION: {
				this._setOrientation(cmd.params);
			}
			case CESIUM_ACTION.LOAD_3DTILES: {
				break;
			}
			case CESIUM_ACTION.MEASURE: {
				break;
			}
		}
	}

	private _flyTo(params: any) {
		let position = params.position;
		this._earth.flyTo(
			{
				lng: position.longitude,
				lat: position.latitude,
				alt: position.height,
			},
			params.orientation
		);
	}

	private _setView(params: any) {
		let position = params.position;
		this._earth.setView(
			{
				lng: position.longitude,
				lat: position.latitude,
				alt: position.height,
			},
			params.orientation
		);
	}

	private _setOrientation(params: any) {
		this._earth.setOrientation(params.orientation);
	}
}

export default Executor;
